<template>
  <view class="search-input">
    <el-input v-model="inputVal" :placeholder="$t(`global.search`)" :prefix-icon="Search" @input="search">
      <template #suffix v-if="hasScan">
        <FullScreen style="width: 30rpx;" color="#000" @click.stop="scanProduct" id="scan" />
      </template>
    </el-input>
  </view>
</template>
  

<script lang="ts" setup>
import { ref } from 'vue'
import { Search, FullScreen } from '@element-plus/icons-vue'
const inputVal = ref('')
defineProps({
  hasScan: {
    type: Boolean,
    default: true
  }
})

const emits = defineEmits(['search'])
const scanProduct = () => {
  uni.webView.postMessage({
    data: 'pages/hkb/product/list'
  })
}

const search = () => {
  emits('search', inputVal.value)
}
onShow((e) => {
  const pages = getCurrentPages();
  inputVal.value = pages[pages.length - 1].$page.options.goodsnum
  search()
})
</script>